package com.robot.mvvm.ui.my

import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants
import com.robot.base.utils.ChoiceImgHelper
import com.robot.mvvm.BR
import com.robot.mvvm.R
import com.robot.mvvm.databinding.AppActivityPersonalInfoBinding
import com.robot.mvvm.vm.my.PersonalInfoViewModel

@Route(path = AppConstants.Router.Main.A_PERSONAL_INFO)
class PersonalInfoActivity :
    GLBaseActivity<AppActivityPersonalInfoBinding, PersonalInfoViewModel>() {
    override fun initContentView(savedInstanceState: Bundle?): Int =
        R.layout.app_activity_personal_info

    override fun initVariableId(): Int = BR.viewModel

    override fun initComponents() {
        addSingleTitleBar(
            getString(R.string.app_tips_27), getString(R.string.app_tips_33)
        )

        viewModel.initData()
    }

    override fun initViewObservable() {
        super.initViewObservable()
        viewModel.getUC().onRightEvent.observe(this) {
            viewModel.type.set(!(viewModel.type.get() ?: false))
            tvRightTitle.text = if (viewModel.type.get() == true) {
                getString(R.string.app_tips_34)
            } else {
                getString(R.string.app_tips_33)
            }

            if(viewModel.type.get() == false){
                viewModel.save()
            }
        }
        viewModel.uc.updateAvatarEvent.observe(this) {
            ChoiceImgHelper.choice(
                this,
                1,
                false,
                {
                    it.forEach { it1 ->
                        viewModel.upload(it1?.compressPath ?: "") {
                            viewModel.imgUrl.set(it)
                        }
                    }
                },
                {

                }
            )
        }

    }
}